
import { WeElement, define } from 'omi'

import './index.css'
import {post} from '../../utils/util.js'
import {UploadInvoice} from '../../api/api.js'
const app = getApp();
import '../../components/order-type-picker'
import '../../components/time-picker'
define('page-logs', class extends WeElement {
  config = {
    navigationBarTitleText: '预约发票'
  }
  counterChange = (evt)=> {
    console.log(evt.detail)
  }
  data = {
    datail:"",
    date:'',
    address:'',
    phone:'',
    bank_name:'',
    account:''
  }
  install(options) {
    this.data.num=1
    this.data.type=1
    this.update()
    console.log(options)
  }
  // 个人
  num1 = () => {
   this.data.num=1
    this.update()
  }
  // 单位
  num2 = () =>  {
    this.data.num=0
    this.update()
  }
  // 获取微信发票抬头
  wxtitle=()=>{
    wx.chooseInvoiceTitle({
      success:(res)=>{
        console.log('发票抬头',res)
        this.data.address = res.companyAddress;
        this.data.phone = res.telephone;
        this.data.bank_name = res.bankName;
        this.data.account = res.bankAccount;
        this.update();
      },
      fail:(res)=>{
        if(res.errMsg.includes("fail")){
             
        }
      }
    })
  }
  type=(e)=>{
    this.data.datail=e.detail.date
    this.update()
  }

  choose_date=(e)=>{
    this.data.date=e.detail.date;
    this.update();
  }

  //上传发票信息
  upload_invoice=(e)=>{
    const { num, datail, date, address, phone, bank_name, account} = this.data;
    const { name, head_name, duty_paragraph, remarks} = e.detail.value;
    console.log(e.detail.value)
    post(UploadInvoice,{
      name: name,
      type_name: datail,
      time: date,
      head_type: num,
      duty_paragraph: duty_paragraph,
      address: address,
      phone: phone,
      bank_name: bank_name,
      account: account,
      remarks: remarks
    })
  }

   render() {
     const { datail} = this.data;
    return (
      <form class="bgcolor" bindsubmit={this.upload_invoice}>
      <view class="font_color">
      <view class="glob">
        <view class="marg">
          <text class="datail_title">开票人信息</text>
        </view>
      </view>
        <view class="detail">
          <view class="margi">
            <text class="width_text">姓名</text>
            <input class="inp" type="text" placeholder="请输入开票人姓名" name="name" />
          </view>
        </view>
        <view class="detail" >
          <view class="margi">
            <text>类型</text>
              <view class="flex_right">
                <order-type-picker onChoosetype={this.type} class="inline_right" />
                <text class="gt">></text>
              </view>
             
          </view>
        </view>
        {
            datail && <view class="detail">
              <view class="margi">
                <text class="width_text">{datail}</text>
                {
                  datail=="房间号"&&<input class="inp" type="text" placeholder="请输入您的房间号" />
                }
                {
                  datail == "包厢号" && <input class="inp" type="text" placeholder="请输入您的包厢号" />
                }
                {
                  datail == "桌号" && <input class="inp" type="text" placeholder="请输入您的桌号" />
                }
                
              </view>
            </view>
        }
        <view class="detail">
          <view class="margi">
            <text>取票时间</text>
              <view class="flex_right">
                <time-picker onclass="inline_right" onChoosedate={this.choose_date} />
                <text class="gt">></text>
              </view>
          </view>
        </view>
        <view class="xinx">
            <text class="datail_title">发票信息</text>
        </view>
        <view class="fap_lei">
            <text class="datail_title">发票类型</text>
        </view>
        <view class="detail bor_but">
          <view class="margi">
              <text class="datail_title">发票抬头</text>
              <view class="flex_right">
              <text class="lei" onClick={this.wxtitle}>请选择微信发票抬头</text>
                <text class="gt">></text>
              </view>
          </view>
        </view>
        <view class="two_but ">
          <view class="left_but">
              <text class={this.data.num == 1 && 'active'} onClick={this.num1}>个人</text>
          </view>
          <view class="right_but " >
              <text class={this.data.num == 0 && 'active'} onClick={this.num2}>单位</text>
          </view>
        </view>
        <view class="detail mar_top">
          <view class="margi">
            <text>抬头名称</text>
              <input class="det_inp" type="text" placeholder="请输入抬头名称" name="head_name" />
          </view>
        </view>
        {
            this.data.num == 0 && <view class="detail ">
              <view class="margi">
                <text>税号</text>
                <input class="det_inp" type="text" placeholder="请输入税号" name='duty_paragraph' />
              </view>
            </view>
        }
        <view class="xinx">
          <text>备注</text>
        </view>
        <view class="beiz">
            <input type="text" placeholder="特殊要求、额外消费" name="remarks" />
        </view>
      </view>
        <button form-type='submit' class="buttom_but">
        <text>提交预约</text>
      </button>
      </form>
    )
  }
})